<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%-- 引入页面头 --%>
<%@ include file="/pageHead.jsp"%>

<form name="form1" id="form1" action="" method="post">
	<div class="pageMain">
		<div class="pageTitle"><%=MessageResourcesUtils.getMessage(request, "systemmanage.bascsetting.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "systemmamage.dutymanage.dutyset.dutyList.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "systemmamage.dutymanage.dutyset.dutyView.title") %></div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i></i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmamage.dutymanage.dutyset.dutyList.dutycode") %></label>
						<span><input type="text" id="dutycode" name="dutycode" value="${duty.dutycode}" readonly="readonly" /></span>
					</li>
					<li>
						<i></i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmamage.dutymanage.dutyset.dutyList.dutyname") %></label>
						<span><input type="text" id="dutyname" name="dutyname" value="${duty.dutyname}" readonly="readonly"/></span>
					</li>
				</ul>
			</div>	
			<!-- 分配服务菜单权限 start -->
			<div  style="border: 1px solid #e0e0e0;background:#fff;padding-top: 9px;height:350px;width: 99%;">
				<span style="color: red;padding-left: 5px;padding-right: 6px"></span><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesAdd.fenpeimenu") %>
	       		<div  style="margin-top: 9px;height:300px;overflow-y:auto;">
	       			<ul id="menuTree" class="ztree" style="padding-left: 13px;"></ul>
	       		</div>
       		</div>
	       	<!-- 分配服务菜单权限end -->
	       		
		</div>
		<div class="button-group" style="padding-top: 10px">
        		<input type="hidden" id="menu_ids" name="menu_ids" value="${menu_ids}"/>
        		<input type="hidden" id="id" name="id" value="${duty.id}"/>
        		<input type="hidden" id="menuid_all" name="menuid_all" value="${menuid_all}"/>
       			<input type="button" class="btn btn-default"  id="butReturn" name="butReturn" value='<%=MessageResourcesUtils.getMessage(request, "common.button.back") %>' />
			</div>
	</div>
</form>

<script type="text/javascript">	
$(document).ready(function() {
	/****************获取菜单节点 start*******************/
	function asyncMenu(){
		var treeAllArray;
		var treeArray;
		var treeList=$("#menu_ids").val();//获得从后台传来的所有菜单ID
		var treeAllList=$("#menuid_all").val();
        var zTree = $.fn.zTree.getZTreeObj("menuTree");
        if(treeList != ""){
        	if(treeList.lastIndexOf(",")>0){
				treeArray=treeList.split(",");
			}else{
				treeArray=new Array(treeList);	
			}
			if(treeAllList.indexOf(",")>0){
				treeAllArray=treeAllList.split(",");
			}else{
				treeAllArray=new Array(treeAllList);	
			}
        }
       
		asyncMenuNodes(zTree.getNodes());
		if(treeArray != ""){
			for(var i=0;i<treeArray.length;i++){
				var node = zTree.getNodeByParam("menuid",treeArray[i]);
				if(node == null){
					continue;
				}
				if(node.isParent){
					continue;
				}
				zTree.checkNode(node, true, true);
				zTree.updateNode(node); 
				
				//判断是否循环treeArray中最后一条数据
				if(i == treeArray.length - 1){
					//根据后来传来的菜单ID是否在节点树种，若存在则禁用它
					for(var i =0;i<treeAllArray.length;i++){
						var node = zTree.getNodeByParam("menuid",treeAllArray[i]);
						if(node == null){
							 continue;
						}
						if(node.isParent){
							continue;
						}
						zTree.setChkDisabled(node, true, true, false);
					} 
				}
			}
		}
	}
	
	function asyncMenuNodes(nodes){
		if(!nodes) return;
		var zTree = $.fn.zTree.getZTreeObj("menuTree");
		for (var i=0, l=nodes.length; i<l; i++) {//遍历外层节点
			if (nodes[i].isParent && nodes[i].zAsync) {//如果是父节点并且父节点没有加载过
				asyncMenuNodes(nodes[i].children);//在这种条件下继续递归遍历该父节点的所有子节点
			} else {//如果不是父节点或者父节点已经加载过
				zTree.reAsyncChildNodes(nodes[i], "refresh", true);//清空后不展开父节点，其他值或缺省状态都自己展开
			}
		}
	}
	
	var menusetting = {
			async: {
				enable:true,
				url:"${systemctx}/systemmamage/dutymanage/dutyset/queryMenuDirectoryTree.json?view=view",
				autoParam: ["menucode","menulevel"]
			},check:{
				enable:true,
				chkDisabledInherit: true
			},data:{
				simpleData:{
					enable:true,
					idKey:"menucode",
					rootPid:0
				}
			},callback:{
				onAsyncSuccess:asyncMenu
			}
	};
	
	$.fn.zTree.init($("#menuTree"), menusetting);//初始化zTree，第三个参数没有则表明用异步加载
	var zTree2 = $.fn.zTree.getZTreeObj("menuTree");
	zTree2.setting.check.chkboxType = { "Y" : "ps", "N" : "ps" };//checkbox（Y）勾选后和取消（N）都对父节点（p）和对子节点（s）有影响
	/****************获取菜单节点end*******************/
	
	$('#butReturn').click(function(){
		parent.document.location.reload();
	    $.fn.closeIssWindow();
	});
});
</script>
<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>